package com.bocloud.cmp.web.controller.app.resource;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bocloud.common.enums.BoCloudMethod;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BsmResult;
import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.MapTools;
import com.bocloud.registry.http.core.ServiceFactory;
import com.bocloud.registry.http.model.RemoteService;

/**
 * openshift监控web的控制层
 * 
 * @author Zaney
 * @data:2017年3月31日
 * @describe:
 */
@RestController
@RequestMapping("/openshift/monitor")
public class OpenshiftMonitorController {
	private final String BASE_SERVICE = "/openshift/monitor";
	private static final BoCloudService SERVICE = BoCloudService.Cmp;
	@Autowired
	private ServiceFactory serviceFactory;
	/**
	 * pod/node监控
	 * @param params
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/kubernetes/monitor", method = { RequestMethod.GET })
	public BsmResult kubernetesMonitor(@RequestParam(value = Common.PARAMS, required = true) String params,
			HttpServletRequest request){
		String url = BASE_SERVICE + "/kubernetes/monitor";
		Map<String, Object> paramMap = MapTools.simpleMap(Common.PARAMS, params);
		RemoteService service = serviceFactory.safeBuild(SERVICE, url, BoCloudMethod.BASIC, null, paramMap, request);
		return service.invoke();
	}
	/**
	 * application监控
	 * @param params
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/app/monitor", method = { RequestMethod.GET })
	public BsmResult appMonitor(@RequestParam(value = Common.PARAMS, required = true) String params,
			HttpServletRequest request){
		String url = BASE_SERVICE + "/app/monitor";
		Map<String, Object> paramMap = MapTools.simpleMap(Common.PARAMS, params);
		RemoteService service = serviceFactory.safeBuild(SERVICE, url, BoCloudMethod.BASIC, null, paramMap, request);
		return service.invoke();
	}
}
